package com.edu.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @Author:mx
 * @Date:2025/10/29-16:18:10
 */
public class Emp implements BeanNameAware, ApplicationContextAware {

    private int empId;

    private String empName;

    private double salary;

    private Depart depart;

    private String beanName;

    public String getBeanName() {
        return beanName;
    }

    public Depart getDepart() {
        return depart;
    }

    public void setDepart(Depart depart) {
        System.out.println("给员工设置了指定的部门");
        this.depart = depart;
    }

    public double getSalary() {
        if(depart.getDepartId() == 1){
            this.salary =  6000;
        }else if(depart.getDepartId() == 2){
            this.salary = 5000;
        }else{
            this.salary = 4000;
        }
        return this.salary;
    }

    public int getEmpId() {
        return empId;
    }

    public void setEmpId(int empId) {
        this.empId = empId;
    }

    public String getEmpName() {
        return empName;
    }

    public void setEmpName(String empName) {
        this.empName = empName;
    }

    public Emp() {
        System.out.println("执行了emp的构造方法");
    }

    @Override
    public String toString() {
        return "Emp{" +
                "empId=" + empId +
                ", empName='" + empName + '\'' +
                '}';
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("spring 容器调用了 beanNameAware接口的方法");
        this.beanName = s;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("容器是"+applicationContext);
    }
}
